<template lang="jade">

	div.news_page.top(v-infinite-scroll="down()" , infinite-scroll-disabled="busy", infinite-scroll-distance="10")

		div.top_com_type.cbox
			div.cl.type
				ul#newsmenu
					li(v-bind:class="{ 'on':newstype=='188' }", v-on:click="setNewsType('188')") 投资资讯
					li(v-bind:class="{ 'on':newstype=='195' }", v-on:click="setNewsType('195')") 网贷学堂
					li(v-bind:class="{ 'on':newstype=='203' }", v-on:click="setNewsType('203')") 政策法规
					li(v-bind:class="{ 'on':newstype=='179' }", v-on:click="setNewsType('179')") 网站公告
					li(v-bind:class="{ 'on':newstype=='186' }", v-on:click="setNewsType('186')") 评估报告

			div.cl.icon
				i.iconfont(@click="showPop()") &#xe62f;

		popup(:show.sync="pop_show", height="100%")
			div.news_type_popup
				h2 选择频道
					i.iconfont(@click="hidePopup()") &#xe643;
				div.typelist
					ul(v-for="  (index, a) in ntypeData ")
						li(v-for=" b in a.sublist[index] ", v-on:click="setNtype(b.id)") {{b.name}}



		swiper(:list="banner", :aspect-ratio="300/750", :auto="true")


		ul.news_list(v-if= " newstype =='186' ")
			li(v-for=" item in items " , v-link="{ name: 'report', params: { reportId: item.apply_id } }"  )
				span.title {{item.name}}
				span.fr.time {{item.initial_assess_time}}

		ul.news_list(v-else)
			li(v-for=" item in items " , v-link="{ name: 'newsDetail', params: { newsId: item.id } }")
				span.title {{item.title}}
				span.fr.time {{item.insert_time}}
				//span.fr {{item.source}}
</template>

<style>
@import '~vux/dist/vux.css';
</style>


<script>
import '../assets/sass/news/news.scss'

import {c_is_logined, c_article_list, c_article_banner, Api_Report_List} from '../config/api'
import api from '../data/api';

import {Popup, Swiper} from 'vux'

export default{
	//props:['show_loading', 'phone'],
	data(){
		return{
			newstype:"",
			ntype:"",
			busy:false,
			items: [],
			obj: [],
			page:1,
			pop_show:false,
			banner:[],
			ntypeData:[]
		}
	},

	components: {
		Popup,
		Swiper
	},

	methods:{
		hidePopup(){
			this.pop_show = false;
		},
		showPop(){
			this.pop_show = true;
		},
	    getList: function (key) {
			this.newstype = key;
			this.busy = true;
			//this.items=this.obj=[];
			this.page=1;
	    },



	    setNewsType(key){
	    	this.newstype = key;
	    	this.ntype = '';
	    	this.pop_show = false;
	    	this.items=[];

	    	//this.fetch(1);
			if(key=="186")
				this.report(1);
			else
				this.fetch(1);
	    },

	    setNtype(key){
	    	this.ntype = key;
	    	this.newstype = key;
	    	this.pop_show = false;
	    	this.items=[];

	    	//this.fetch(1);
			if(key=="186")
				this.report(1);
			else
				this.fetch(1);
	    },


		down: function() {

		  if(this.busy == true || this.items == ''){
		    return false;
		  }
		  this.busy = true;
		  if(this.newstype=="186")
		  	this.report(++this.page);
		  else
		  	this.fetch(++this.page);
		},


	    report: function (page) {
	      var data = {'page': page}
	      this.$http({url: Api_Report_List+'&page='+page, method: 'GET'}).then(function (response) {
	      	//this.items = response.data.data.list;
	      	this.items = this.items.concat(response.data.data);
	      	this.busy = false,this.$store.dispatch('setShowLoading', false);
	      });
	    },


		async is_login(){
			var res = await api.user.is_Logined();
			if(res.status == true ){
				this.$store.dispatch('setPhone', res.phone);
			}
		},



	    fetch: function (page) {
	      var data = {'page': page}
	      this.$http({url: c_article_list+'&number=20&page='+page+'&pid='+this.newstype+'&id='+this.ntype, method: 'GET'}).then(function (response) {
	      	//this.items = response.data.data.list;
	      	this.items = this.items.concat(response.data.data.list);
	      	this.busy = false,this.$store.dispatch('setShowLoading', false);
	      });
	    },

	    fbanner() {
	      this.$http({url: c_article_banner+'&id='+this.newstype, method: 'GET'}).then(function (response) {
	      	this.banner = response.data.data.banner;
	      	for(var i in this.banner){
	      		this.banner[i].url = '/news/detail/'+this.banner[i].article_id
	      	}

	      	this.is_login();
	      });
		},

		async getNewsType(){
			var res = await api.news.typelist();
			if(res.status){
				this.ntypeData = res.data;
			}
		}
	},
	route: {
		activate ( transition ) {
			//console.log( this.$route)
			//this.header = true, this.tabbar = true;
			document.title = "资讯频道 - 有喜财富手机版"
			this.$store.dispatch('setShowLoading', true);

			if(transition.to.params.ntype=="index" || transition.to.params.ntype=="index" )
				this.newstype = "";
			else
				this.newstype = transition.to.params.ntype

			transition.next();

			if( this.newstype =="186" )
				this.report(1);
			else
				this.fetch(1);

			//this.fetch(1);
			this.fbanner();


			this.getNewsType();


		}
	}
}
</script>
